package com.cx.config;

import com.cx.redis.RedisUtil;
import lombok.extern.slf4j.Slf4j;


@Slf4j
public class TransThread extends Thread {

    private String k;
    private LcnConnection lcnConnection;

    public TransThread(String k, LcnConnection lcnConnection){
        this.k=k;
        this.lcnConnection = lcnConnection;
    }


    @Override
    public void run() {
        boolean iscon = true;
        while (iscon){
            String r = RedisUtil.getObject(k);
            log.debug("等待>>>>>"+r+"key:"+k);
            if ("commit".equalsIgnoreCase(r)){
                iscon = false;
                lcnConnection.notify(1);
                log.error("事务成功>>>>>");
                break;
            }else if ("rollback".equalsIgnoreCase(r)){
                lcnConnection.notify(2);
                iscon = false;
                log.error("事务失败>>>>>");
                break;
            }else {
                continue;
            }
        }
    }
}
